package com.uuyun.preview.entity;

import com.uuyun.preview.responseData.EnumErrorCode;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import static com.uuyun.preview.responseData.EnumErrorCode.SUCCESS;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {

    /**
     * 返回值
     */
    Integer code;

    /**
     *补充信息
     */
    String msg;

    /**
     * 接口请求结果
     */
    T data;


    public static Result success() {
        Result resultMsg = new Result();
        resultMsg.setCode(SUCCESS.getCode());
        resultMsg.setMsg("");
        return resultMsg;
    }

    public static Result success(String msg, Object data) {
        Result resultMsg = new Result();
        resultMsg.setCode(SUCCESS.getCode());
        resultMsg.setMsg(msg);
        resultMsg.setData(data);
        return resultMsg;
    }

    public static Result success(String msg) {
        Result resultMsg = new Result();
        resultMsg.setCode(SUCCESS.getCode());
        resultMsg.setMsg(msg);
        resultMsg.setData(null);
        return resultMsg;
    }

    public static Result error(String message) {
        return error(500, message);
    }

    public static Result error(int code, String message) {
        Result resultMsg = new Result();
        resultMsg.setCode(code);
        resultMsg.setMsg(message);
        return resultMsg;
    }

    public static Result error(int code, String message, Object data) {
        Result resultMsg = new Result();
        resultMsg.setCode(code);
        resultMsg.setMsg(message);
        resultMsg.setData(data);
        return resultMsg;
    }

    public static Result error(EnumErrorCode code, Object... data) {
        return error(code.getCode(), code.getMessage(), data);
    }

}
